let format = (n) => {
  let num = n.toString();
  let len = num.length;
  if (len <= 3) {
    return num;
  } else {
    let remainder = len % 3;
    if (remainder > 0) {
      // 不是3的整数倍
      console.log(num.slice(remainder, len).match(/\d{3}/g));
      return (
        num.slice(0, remainder) +
        "," +
        num.slice(remainder, len).match(/\d{3}/g).join(",")
      );
    } else {
      // 是3的整数倍
      console.log(num.slice(0, len).match(/\d{3}/g));
      return num.slice(0, len).match(/\d{3}/g).join(",");
    }
  }
};
// format(232323); // '1,232,323'
let arr = '1234567'
console.log(arr.match(/\d{3}/g))
